package util.functors;

import org.apache.commons.functor.UnaryFunction;
import org.apache.commons.functor.adapter.RightBoundFunction;

/*
 * http://commons.apache.org/functor/
 * http://www.ibm.com/developerworks/java/library/j-fp/index.html
 * http://apachecommonstipsandtricks.blogspot.jp/2009/01/examples-of-functors-transformers.html
 * 
 */
public class TestBFunc {

	public static class SETLItem {
		private String category;
		private String code;
		private String name;
		private int price;

		public String getCategory() {
			return category;
		}

		public String getCode() {
			return code;
		}

		public String getName() {
			return name;
		}

		public int getPrice() {
			return price;
		}

		public void setCategory(String inCategory) {
			category = inCategory;
		}

		public void setCode(String inCode) {
			code = inCode;
		}

		public void setName(String inName) {
			name = inName;
		}

		public void setPrice(int inPrice) {
			price = inPrice;
		}
	}

	public static void main(String[] args) {
		try {
			double discountRate = 0.1;
			double taxRate = 0.33;
			SETLItem item = new SETLItem();
			item.setPrice(100);
			UnaryFunction calcDiscountedPrice = new RightBoundFunction(
					new Multiply(), new Double(1 - discountRate));
			UnaryFunction calcTax = new RightBoundFunction(new Multiply(),
					new Double(1 + taxRate));
//			CompositeUnaryFunction calcNetPrice = new CompositeUnaryFunction(
//					calcTax, calcDiscountedPrice);
//			Double netPrice = (Double) calcNetPrice.evaluate(new Double(item
//					.getPrice()));
//			System.out.println("The net price is: " + netPrice);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}